
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/components/app/app_ripple_button.dart';
import 'package:interview/config/app.enum.dart';
import 'package:interview/controller/navigation_controller.dart';
import 'package:interview/theme/app_colors.dart';
import 'package:interview/utils/logger.dart';

class MineMenu extends StatefulWidget {
  final AppColors theme;
  const MineMenu({super.key, required this.theme});

  @override
  State<MineMenu> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MineMenu> {
  final navigation = Get.find<NavigationController>();
  final List<Map<String, dynamic>> menuList = [
    {"path": "ic_mine_history.png", "text": "历史记录" },
    {"path": "ic_mine_collect.png", "text": "我的面经" },
    {"path": "ic_mine_like.png", "text": "我的试题" },
    {"path": "ic_mine_study.png", "text": "累计学时" }
  ];


  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 6 ,vertical: 8),
      decoration: BoxDecoration(
        color: widget.theme.subjectMix1,
        borderRadius: BorderRadius.circular(12)
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: List.generate(menuList.length,(index){
          final menu = menuList[index];
          return _menuItem(
            path: menu["path"] , 
            text: menu["text"] , 
            theme:widget.theme ,
            onTap: () => _onMenuTap(index), // 添加点击事件
          );
        }),
      ),
    );
  }

  void _onMenuTap(int index){
    final selectedItem = menuList[index];
    Logger.info("$selectedItem" , tag:"_onMenuTap" );
    if(selectedItem["text"] == "我的试题"  ){
      navigation.pushWithAuth("/optpage");
    }
  }


  Widget _menuItem({
    required String path,
    required String text,
    required AppColors theme,
    required VoidCallback onTap,
  }){
    return AppRippleButton(
      onTap: onTap,
      rippleRadius:BorderRadius.circular(8),
      borderRadius:BorderRadius.circular(8),
      backgroundColor: theme.subjectMix1!,
      splashColor:theme.contrastMix3!.withOpacity(0.2),
      highlightColor:theme.subjectMix1!.withOpacity(0.1),
      child: Container(
        padding: const EdgeInsets.all(12),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset('${AppEnumAssets.basePath}$path' , width: 24 , height: 24),
            const SizedBox(height: 12),
            Text(text, style: TextStyle(fontSize: 12 , fontWeight: FontWeight.w500, color: theme.contrastMix3))
          ],
        ),
      )
    );
  }
}